package com.credit.jumu.calculator.utils;

import com.credit.jumu.calculator.bean.OtherResultInfo;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by Administrator on 2017/11/27/027.
 */

public class StringHandleUtil {


	//strting转float
	public static double toInt(String str) {
		try {
			double f = Float.parseFloat(str);
			return f;
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	//strting转float
	public static int toInts(String str) {
		try {
			int f =  Integer.parseInt(str);
			return f;
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	//判断大小
	public static double toOnlyTwo(double d) {
		try {
			if (d <= 0) {
				return 0;
			} else {
				return d;
			}
//			DecimalFormat df = new DecimalFormat("##0.00");
//			return toInt(df.format(d));
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	//保留两位
	public static String toOnlyHavaTwo(double d) {
		try {
			DecimalFormat df = new DecimalFormat("##0.00");
			return df.format(d).toString();
		} catch (NumberFormatException e) {
			return "";
		}
	}
	//保留返回du
	public static double toOnlytwoDouble(double d) {
		try {
			DecimalFormat df = new DecimalFormat("##0.00");
			return toInt(df.format(d).toString());
		} catch (NumberFormatException e) {
			return 0;
		}
	}
}
